//斐波那契数列

#include <stdio.h>
long long function1(int n);
void function2(int n2);
long long function3(int n3);

int main ()
{
    //第n项
    int n = 9;
    //第n项值number
    long long number = function1(n);
    printf("第%d项是%lld.\n",n,number);
    printf("--------------------\n");

    //打印前nn项
    int nn = 26;
    function2(nn);
    printf("\n");
    printf("--------------------\n");

    //计算前nnn项的和
    int nnn = 5;
    long long res = function3(nnn);
    printf("前%d项的和为%lld.\n",nnn,res);
}

//计算斐波那契数列的第n项
//1,1,2,3,5,8,13...  
//递归
long long function1(int n1)
{
    if(n1 == 1 || n1 == 2)
    {
        return 1;
    }
    return function1(n1 - 1) + function1(n1 - 2);
}

//输出斐波那契数列的前n项
//利用function1找出斐波那契数列的每一项，并循环输出
void function2(int n2)
{
    int count = 0;
    for (int i = 1; i <= n2; i++)
    {
        int each_number = function1(i);
        count++;
        printf("%d ",each_number);
        if (count == 8)
        {
            printf("\n");
            count = 0;
        }
    }
}

//计算前n项斐波那契数列的和
//利用function1找出斐波那契数列的每一项，并累加求和
long long function3(int n3)
{
    int total = 0;
    for (int i = 1; i <= n3; i++)
    {
        int each_result = function1(i);
        total +=each_result;
    }
    return total;
}